import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core';
import { ConfirmDialogService } from './confirm-dialog.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-confirm-dialog',
  templateUrl: './confirm-dialog.component.html',
  styleUrls: ['./confirm-dialog.component.scss']
})

/**
 * 描述：确认框TS
 * 作者：oyjl
 * 时间：2020-04-28 16:42:53
 */
export class ComfirmDialogComponent implements OnInit {

  constructor(
    public confirmDialogService: ConfirmDialogService,
    public router: Router) { }

  ngOnInit() {
  }

  /**
   * 描述：确认按钮方法调用
   * 作者：oyjl
   * 时间：2020-04-28 16:58:44
   */
  public confirmHandle() {
    this.confirmDialogService.showConfirmDialog = false;
    if (this.confirmDialogService.accept) {
      this.confirmDialogService.accept();
    }
    this.sessionExpire();
  }

  /**
   * 描述：关闭弹框
   * 作者：oyjl
   * 时间：2020-04-28 17:31:54
   */
  public closeDialog() {
    this.confirmDialogService.showConfirmDialog = false;
    this.sessionExpire();
  }

  /**
   * 描述：会话过期处理
   * 作者：oyjl
   * 时间：2020-05-07 14:37:39
   */
  public sessionExpire() {
    if (this.confirmDialogService.contentText.includes('会话过期')) {
      this.router.navigateByUrl('/mobile/login');
      sessionStorage.clear();
    } else if (this.confirmDialogService.contentText.includes('成功')) {
      history.back();
    } else { }
  }
}
